import base64
from typing import List

import shortuuid
from peewee import JOIN

from afast_core.core_libs.captcha.cilent import generate_captcha
from afast_core.core_tools.jwt_helper import SimpleAuth
from infirmary_admin_src.infirmary_common.infirmary_controller import IAsyncSessionBaseController, IBaseController
from infirmary_admin_src.infirmary_common.infirmary_controller.rest_controller_with_depends import \
    RestControllerWithDepends
from fastapi import Request, Depends, Path, Body
from afast_core.core_tools import json_helper
from infirmary_admin_src.infirmary_smart_admin.infirmary_biz.infirmary.businesses.schemas import SchemaBase
from infirmary_admin_src.infirmary_smart_admin.infirmary_biz.support.services import SupportBusinesses


class XParam(SchemaBase):
    '''
    账号密码登录参数
    '''
    create_time: str = Body('', alias='createTime', title="create_time", description='创建时间')
    deleted_flag: bool = Body(False, alias='deletedFlag', title="deleted_flag", description='是否删除标记')
    update_time: str = Body('', alias='updateTime', title="update_time", description='更细时间')
    dict_key_id: int = Body(None, alias='dictKeyId', title="dict_key_id", description='权限类型')
    key_code: str = Body(None, alias='keyCode', title="key_code", description='键编码')
    key_name: str = Body(None, alias='keyName', title="key_name", description='键名称')
    remark: str = Body(None, alias='remark', title="remark", description='备注')
    is_trusted: bool = Body(True, alias='isTrusted', title="is_trusted", description='是否显示')



class IController(IBaseController):
    '''
    定制相关约束检测函数逻辑步序
    '''

    def __init__(self, *, request: Request,
                 schema_param: XParam,
                 ):
        super().__init__(request=request)
        # 入参参数
        # 入参参数
        self.schema_param = schema_param


@RestControllerWithDepends()
class SupportDictKeyAddController(IController):

    def business_login(self):
        pass

        # 自增ID获取
        _id_max_id = {
            'dict_key_id': SupportBusinesses.get_dict_key_id_max_id() + 1,
        }
        # 执行菜单添加
        result = SupportBusinesses.add_dict_key_singe(
            **{**self.schema_param.dict(exclude_unset=True, exclude={'is_trusted'}),
               **_id_max_id})
        if result:
            self.response_msg = '添加成功'
        else:
            self.response_ok = False
            self.response_msg = '添加失败'
            return None

        return None